//
//  LXStatusRetweetView.swift
//  weibo
//
//  Created by lixin on 16/4/22.
//  Copyright © 2016年 lixin. All rights reserved.
//

import UIKit

import SnapKit

class LXStatusRetweetView: UIView {
    
    var retweetViewConstraint: Constraint?
    
    var status: LXStatus?{
       
        didSet{
            
            contentLabel.text = status?.retweeted_status?.text
            
            self.retweetViewConstraint?.uninstall()
            
            if status?.retweeted_status?.pic_ids?.count != 0{
                
                pictureView.pictureInfo = status?.retweeted_status?.pic_ids
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.retweetViewConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                
                pictureView.hidden = false
                
            }else{
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.retweetViewConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
              
                pictureView.hidden = true
            }
            
        }
    }
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 视图设置
    private func setUI(){
        
        self.backgroundColor = RGB(red: 237, green: 237, blue: 237)
        
        addSubview(contentLabel)
        
        addSubview(pictureView)
       
        contentLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.top.equalTo(self).offset(10)
            
            make.width.equalTo(SCREENW - 20)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            
            make.leading.equalTo(contentLabel)
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            
            self.retweetViewConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(10).constraint
        }
    }
    
    
    // MARK: - 懒加载控件
    private lazy var contentLabel: UILabel = {
        
        let label = UILabel(textColor: UIColor.blackColor(), textFont: 14)
        
        label.numberOfLines = 0
        
        return label
    }()
 
    private lazy var pictureView: LXStatusPictureView = LXStatusPictureView()
}
